<template>
    <div>
      <!--form表单-->
      <el-form size="small" ref="formData" :model="formData" label-width="150px">
        <el-form-item label="客服類型">
          <div>
            <el-radio v-model="formData.serviceType" :label="10">聊天工具</el-radio>
            <el-radio v-model="formData.serviceType" :label="20" v-if="formData.serviceOpen==1">線上客服</el-radio>
          </div>
        </el-form-item>
        <div v-if="formData.serviceType==10">
        <el-form-item label="微信號">
          <el-input v-model="formData.wechat" placeholder="請輸入微信號" class="max-w460"></el-input>
        </el-form-item>
        <el-form-item label="qq">
          <el-input v-model="formData.qq" placeholder="請輸入QQ號" class="max-w460"></el-input>
        </el-form-item>
        <el-form-item label="聯絡電話">
          <el-input v-model="formData.phone" placeholder="請輸入聯絡電話" class="max-w460"></el-input>
        </el-form-item>
        </div>
<!--        <el-form-item label="绑定客服" v-if="formData.serviceType==20" :rules="[{required: true,message: '请输入绑定用户id'}]" prop="userId">-->
<!--          <el-input type="number" v-model="formData.userId" placeholder="请输入用户id" class="max-w460" :disabled="userId>0"></el-input>-->
<!--          <p class="gray">请在商城小程序个人中心查看用户ID</p>-->
<!--        </el-form-item>-->
        <!--提交-->
        <div class="common-button-wrapper">
          <el-button size="small" type="primary" @click="onSubmit" :disabled="loading">提交</el-button>
        </div>
      </el-form>
    </div>
  
</template>

<script>
import SettingApi from '@/api/setting.js';
export default {
  data() {
    return {
      /*是否在提交*/
      loading: false,
      /*表单数据对象*/
      formData: {
        serviceType: 10,
        wechat: '',
        qq: '',
        phone: '',
        serviceOpen: '',
        userId: ''
      }
    };
  },
  created() {
    this.getData();
  },
  methods: {
    /*获取配置数据*/
    getData() {
      let self = this;
      SettingApi.getService({}, true).then(res => {
        if (res.data != null) {
          self.formData = res.data;
          self.userId = res.data.userId;
        }
      }).catch(error => {});
    },
    /*提交*/
    onSubmit() {
      let self = this;
      let params = this.formData;
      self.$refs.formData.validate(valid => {
        if (valid) {
          self.loading = true;
          SettingApi.setService(params, true).then(data => {
            self.loading = false;
            ElMessage({
              message: "恭喜您，保存設定成功",
              type: 'success'
            });
          }).catch(error => {
            self.loading = false;
          });
        }
      });
    }
  }
};
</script>

